package com.wht.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wht.domain.DtsPermission;
import com.wht.mapper.DtsPermissionMapper;
import com.wht.service.DtsPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author wanghaotian
 * time:2022/12/01,0001 22:22
 * description:
 */

@Service
public class DtsPermissionServiceImpl implements DtsPermissionService {

    @Autowired
    private DtsPermissionMapper permissionMapper;

    @Override
    public Set<String> queryByRoleIds(Integer[] roleIds) {
        Set<String> permissions = new HashSet<>();
        if(roleIds == null || roleIds.length == 0){
            return permissions;
        }
        QueryWrapper<DtsPermission> wrapper = new QueryWrapper<>();
        wrapper.in("role_id", Arrays.asList(roleIds));
        wrapper.eq("deleted", false);
        List<DtsPermission> permissionList = permissionMapper.selectList(wrapper);
        for (DtsPermission permission : permissionList) {
            permissions.add(permission.getPermission());
        }
        return permissions;
    }
}
